var Api = require('../../utils/api.js');
var app = getApp();
var imageUtil = require('../../utils/util.js');
var WxParse = require('../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    order:[],
  },
  onLoad: function (options) {
     var that = this;
    // 生命周期函数--监听页面加载
    app.getUserInfo(function (userInfo) {
      var user = wx.getStorageSync('user');
      var url = Api.HOST + 'wechat.php?s=Home/record';

      var data = {};
      data.nickname = userInfo.nickName;
      data.headimgurl = userInfo.avatarUrl;
      data.openid = user.openid;
      Api.fetchPost(url, data, (err, res) => {
        that.setData({
          order: res.order,
        });
      });
    })
  },
  scroll: function (e) {
    console.log(e)
  },
  detail: function (e) {
    wx.redirectTo({
      url: '/pages/result/result?id=' + e.currentTarget.dataset.value,
    })
  },
  again: function (e) {
    wx.redirectTo({
      url: '/pages/index/index',
    })
  },
  onShareAppMessage: function (res) {
    console.log(res)
    if (res.from === 'button') {
      // 来自页面内转发按钮
      return {
        title: '大数据征信查询',
        path: '/pages/index/index',
        success: function (res) {
          // 转发成功
          var that = this;

          app.getUserInfo(function (userInfo) {
            var user = wx.getStorageSync('user');
            var url = Api.HOST + 'wechat.php?s=Home/share';

            var data = {};
            data.openid = user.openid;

            Api.fetchPost(url, data, (err, res) => {
              that.setData({

              });
            });
          })

        },
        fail: function (res) {
          // 转发失败
        }
      }
    } else {
      return {
        title: '大数据征信查询',
        path: '/pages/index/index',
        success: function (res) {
          // 转发成功
          var that = this;

          app.getUserInfo(function (userInfo) {
            var user = wx.getStorageSync('user');
            var url = Api.HOST + 'wechat.php?s=Home/share';

            var data = {};
            data.openid = user.openid;

            Api.fetchPost(url, data, (err, res) => {
              that.setData({

              });
            });
          })

        },
        fail: function (res) {
          // 转发失败
        }
      }
    }
  },
})